import type { Metadata, Viewport } from 'next'
import { Noto_Sans, Noto_Sans_SC } from 'next/font/google'
import { notFound } from 'next/navigation'
import { authOptions } from '@/auth'
import { routing } from '@/i18n/routing'
import { getServerSession } from 'next-auth'
import { NextIntlClientProvider } from 'next-intl'
import { getMessages } from 'next-intl/server'
import { cookies } from 'next/headers'
// components
import { Toaster } from '@/components/ui/toaster'

const noto_sans = Noto_Sans({
  weight: ['400', '600', '700'],
  subsets: ['latin'],
  display: 'swap',
  variable: '--font-noto-sans',
})
const noto_sans_sc = Noto_Sans_SC({
  weight: ['400', '500', '600', '700'],
  subsets: ['latin'],
  display: 'swap',
  variable: '--font-noto-sans-sc',
})
export const metadata: Metadata = {
  title: 'RunGood - Replay',
  description: 'tmp_description',
  openGraph: {
    title: 'tmp_title',
    description: 'tmp_description',
    url: 'https://vshop88.com/',
    type: 'website',
  },
  twitter: {
    title: 'tmp_title',
    description: 'tmp_description',
  },
}

export const viewport: Viewport = {
  width: 'device-width',
  initialScale: 1,
  maximumScale: 1,
  minimumScale: 0,
  viewportFit: 'cover',
}

export default async function LocaleLayout({
  children,
  params: { locale },
}: {
  children: React.ReactNode
  params: { locale: string }
}) {
  const isMobile = cookies().get('isMobile')?.value === 'true'

  // Ensure that the incoming `locale` is valid
  if (!routing.locales.includes(locale as never)) {
    notFound()
  }

  // Providing all messages to the client
  // side is the easiest way to get started
  const [messages, session] = await Promise.all([getMessages(), getServerSession(authOptions)])

  return (
    <html lang={locale} className={` ${noto_sans_sc.variable} ${noto_sans.variable} `}>
      <body id="root">
        <NextIntlClientProvider messages={messages}>
          {children}
          <Toaster />
        </NextIntlClientProvider>
      </body>
    </html>
  )
}
